function [maxn, poly, midres, trares, simpres] = question5()
% QUESTION5 - 
%   

    n = 16;
    N = [];
    i =1;
    resp =1;
    while 1
        N =[N,n];
        mid = multimid(@fun,0,1,n);
        res =abs(mid-(-4/9));
        midres(i) =res;
        if res > resp
            maxn(1) = n;
            break;
        end
        resp = midres(i);
        i= i+1;
        n = 2*n;
    end
    l = length(N);
    N = 1./N;
    x = log(N(1:l-2));
    y = log(midres(1:l-2));
    poly(1,:)=polyfit(x,y,1);
    
    n = 16;
    N = [];
    i =1;
    resp =1;
    while 1
        N =[N,n];
        mid = multitra(@fun,0,1,n);
        res =abs(mid-(-4/9));
        trares(i) =res;
        if res > resp
            maxn(2) = n;
            break;
        end
        resp = trares(i);
        i= i+1;
        n = 2*n;
    end
    l = length(N);
    N = 1./N;
    x = log(N(1:l-2));
    y = log(trares(1:l-2));
    poly(2,:)=polyfit(x,y,1);
    
    n = 16;
    N = [];
    i =1;
    resp =1;
    while 1
        N =[N,n];
        mid = multisimp(@fun,0,1,n);
        res =abs(mid-(-4/9));
        simpres(i) =res;
        if res > resp
            maxn(3) = n;
            break;
        end
        resp = simpres(i);
        i= i+1;
        n = 2*n;
    end
    l = length(N);
    N = 1./N;
    x = log(N(1:l-2));
    y = log(simpres(1:l-2));
    poly(3,:)=polyfit(x,y,1);
    

    n = 16;
    N = [];
    i =1;
    resp =1;
    while 1
        N =[N,n];
        mid = Romberg(@fun,0,1,n,2);
        res =abs(mid-(-4/9));
        rom2res(i) =res;
        if res > resp
            maxn(4) = n;
            break;
        end
        resp = rom2res(i);
        i= i+1;
        n = 2*n;
    end
    l = length(N);
    N = 1./N;
    x = log(N(1:l-2));
    y = log(rom2res(1:l-2));
    poly(4,:)=polyfit(x,y,1);
    
    n = 16;
    N = [];
    i =1;
    resp =1;
    while 1
        N =[N,n];
        mid = Romberg(@fun,0,1,n,3);
        res =abs(mid-(-4/9));
        rom3res(i) =res;
        if res > resp
            maxn(5) = n;
            break;
        end
        resp = rom3res(i);
        i= i+1;
        n = 2*n;
    end
    l = length(N);
    N = 1./N;
    x = log(N(1:l-2));
    y = log(rom3res(1:l-2));
    poly(5,:)=polyfit(x,y,1);
    
    n = 4;
    N = [];
    i =1;
    resp =1;
    while 1
        N =[N,n];
        mid = Romberg(@fun,0,1,n,4);
        res =abs(mid-(-4/9));
        rom4res(i) =res;
        if res > resp
            maxn(6) = n;
            break;
        end
        resp = rom4res(i);
        i= i+1;
        n = 2*n;
    end
    l = length(N);
    N = 1./N;
    x = log(N(1:l-2));
    y = log(rom4res(1:l-2));
    poly(5,:)=polyfit(x,y,1);
end

function f = fun(x)
% FUN - 
%   
    sx = size(x);
    f = ones(sx);
    
    for i = 1:sx(1)
        for j = 1:sx(2)
            f(i,j)=sqrt(x(i,j))*log(x(i,j));
        end
    end

end

